package com.gui;

import javax.swing.*;
import javax.swing.border.Border;
import java.awt.*;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;


public class Gui_4 implements ActionListener {
    JButton jButton;
    JFrame jFrame;
//    public static void main(String[] args) {
//        com.gui.Gui_4 gui_4 = new com.gui.Gui_4();
//        gui_4.go();
//    }

    public void go() {
        jFrame = new JFrame();
        jButton = new JButton("click me");

        jButton.addActionListener(this);

        MyPanel myPanel = new MyPanel();
        jFrame.add(BorderLayout.SOUTH,jButton);
        jFrame.add(BorderLayout.CENTER,myPanel);


        jFrame.setDefaultCloseOperation(3);
        jFrame.setSize(300, 300);
        jFrame.setVisible(true);

    }

    @Override
    public void actionPerformed(ActionEvent e) {
        jFrame.repaint();
    }
}

class MyPanel extends JPanel{
    @Override
    public void paint(Graphics g) {
        super.paint(g);

        GradientPaint gradientPaint=new GradientPaint(70,70,Color.blue,150,150,Color.green);
        Graphics2D graphics2D=(Graphics2D) g;
        graphics2D.setPaint(gradientPaint);
        graphics2D.fillOval(70,70,100,100);

    }
}

class MyGui implements ActionListener{
    public static void main(String[] args) {

new MyGui().go();
    }
    JFrame jFrame=new JFrame();
    JButton jb1;
    JButton jb2;
    JLabel jLabel=new JLabel();

    public void go(){
        jb1 = new JButton();
        jb2 = new JButton();
        jb1.addActionListener(this);
        jb2.addActionListener(this);



        MyPanel myPanel = new MyPanel();
        jFrame.add(BorderLayout.SOUTH,jb1);
        jFrame.add(BorderLayout.CENTER,myPanel);


        jFrame.setDefaultCloseOperation(3);
        jFrame.setSize(300, 300);
        jFrame.setVisible(true);
    }

    @Override
    public void actionPerformed(ActionEvent e) {
        if(e.getSource()==jb1){
            jFrame.repaint();
        }else{
            jLabel.setText("that hurt");
        }
    }
}